const { $Message } = require('../../../../utils/iView/base/index');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    phoneno: "",
    address: "",
    mark: "",
  },
  nameChange: function (e) {
    this.setData({ name: e.detail.detail.value })
  },
  phoneChange: function (e) {
    this.setData({ phoneno: e.detail.detail.value })
  },
  addressChange: function (e) {
    this.setData({ address: e.detail.detail.value })
  },
  markChange: function (e) {
    this.setData({ mark: e.detail.detail.value })
  },
  addressAdd: function () {
    let addr = this.data;
    let userID = wx.getStorageSync("cmkc_user_id");
    if (userID) {
      if (addr.name) {
        if (addr.phoneno) {
          if (addr.address) {
            if (addr.mark) {
              wx.showLoading({
                title: '正在添加',
              });
              wx.request({
                url: app.globalData.requestUrl + "5c78f85ba665c",
                data: {
                  name: addr.name,
                  address: addr.address,
                  phoneno: addr.phoneno,
                  mark: addr.mark,
                  user_id: userID
                },
                header: { version: "v3.0" },
                method: 'POST',
                dataType: 'json',
                responseType: 'text',
                success: function (res) {
                  wx.hideLoading();
                  console.log(res);
                  let rd = res.data;
                  if (rd.code == 1) {
                    wx.showModal({
                      title: '提示',
                      content: '新增地址成功',
                      showCancel: false,
                      success: function (res) {
                        wx.navigateTo({
                          url: '/pages/center/address/show/index?address_id=' + rd.data.address_id
                        })
                      }
                    })
                  }
                }
              })
            } else
              $Message({ content: '请填写地址标签', type: 'warning' });
          } else
            $Message({ content: '请填写详细地址', type: 'warning' });
        } else
          $Message({ content: '请填写联系电话', type: 'warning' });
      } else
        $Message({ content: '请填写姓名', type: 'warning' });
    } else {
      $Message({ content: '登录状态已经失效，请重新登录，或者刷新一下', type: 'warning' });
    }
  },
  handleInputChange: function (e) {
    console.log(e)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})